package cn.edu.gdgm.system.service.impl;

import cn.edu.gdgm.system.entity.User;
import cn.edu.gdgm.system.mapper.UserMapper;
import cn.edu.gdgm.system.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 药盒服务用户数据表 服务实现类
 * </p>
 *
 * @author running_hyk
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public boolean existUserByWeChatOpenId(String openId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(User::getWechatOpenId, openId);
        return this.getBaseMapper().selectOne(queryWrapper) != null;
    }

    @Override
    public boolean createUserByWeChatOpenId(String openId) {
        User user = new User();
        user.setWechatOpenId(openId);
        user.setFirstJoinDate(LocalDateTime.now());
        return this.save(user);
    }


}